import { useAppStore } from '@/store'
import { openUrl } from '@/utils'
import {
	WEBSITE_URL,
	AFFILIATE_URL,
	DOWNLOAD_URL,
	HELP_URL,
	TIKTOK_URL,
	FACEBOOK_URL,
	X_URL,
	INSTAGRAM_URL,
	YOUTUBE_URL,
	LICENSE_URL,
	PRIVACY_POLICY_URL,
	TERMS_OF_SERVICE_URL
} from '@/constants'

export const goAffiliate = () => {
	const appStore = useAppStore()
	openUrl(AFFILIATE_URL + '?lang=' + appStore.lang)
}

export const goWebsite = () => {
	const appStore = useAppStore()
	openUrl(WEBSITE_URL + '?lang=' + appStore.lang)
}

export const goDownload = () => {
	openUrl(DOWNLOAD_URL)
}

export const goHelp = () => {
	const appStore = useAppStore()
	const lang = appStore.lang === 'zh' ? 'zh-CN' : appStore.lang
	openUrl(HELP_URL + '/' + lang)
}

export const goLicense = () => {
	if ((window as any).__anj?.domain) {
		const a = document.querySelector(
			'#anj-94f6c769-fa1c-4f4d-ae55-bc16f777ee98 a'
		) as HTMLLinkElement
		if (a) {
			a.target = (window as any).__anj?.params ? '_self' : '_blank'
			a.click()
		}
	} else {
		const appStore = useAppStore()
		openUrl(LICENSE_URL + '?lang=' + appStore.lang)
	}
}

export const goTiktok = () => {
	openUrl(TIKTOK_URL)
}

export const goFacebook = () => {
	openUrl(FACEBOOK_URL)
}

export const goX = () => {
	openUrl(X_URL)
}

export const goInstagram = () => {
	openUrl(INSTAGRAM_URL)
}

export const goYoutube = () => {
	openUrl(YOUTUBE_URL)
}

export const goPrivacyPolicy = () => {
	openUrl(PRIVACY_POLICY_URL)
}

export const goTermsOfService = () => {
	openUrl(TERMS_OF_SERVICE_URL)
}
